import keyboard

x, y = 0, 0


def on_key(event):
    global x, y
    if event.name == 'up':
        print('机器人正在前进')
        y = y + 1
    elif event.name == 'down':
        print('机器人正在后退')
        y = y - 1
    elif event.name == 'left':
        print('机器人正在左转')
        x = x - 1
    elif event.name == 'right':
        print('机器人正在右转')
        x = x + 1
    print("当前位置", str(x), str(y))
    if x == 10 and y == 10:
        print("到达终点")
        exit()


keyboard.on_press(on_key)
keyboard.wait()
